<!--
 * @author: Victor
 * @Date: 2021-01-29 21:39:51
 * @LastEditTime: 2021-02-20 18:16:15
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>视频添加</title>
    <link rel="stylesheet" href="lib/bootstrap.min.css" />
    <link rel="stylesheet" href="lib/notiflix-1.3.0.min.css" />
    <script src="lib/jquery.min.js"></script>
    <script src="lib/notiflix-1.3.0.min.js"></script>
  </head>
  <body style="padding: 15px">
    <h2 class="text-center">黑马导师授课视频审核程序</h2>
    <div class="panel panel-primary">
      <div class="panel-heading">
        <h3 class="panel-title">视频添加</h3>
      </div>
      <div class="panel-body">
        <form class="form-horizontal" id="add">
          <div class="form-group">
            <label for="campus" class="col-sm-2 control-label">校区</label>
            <div class="col-sm-10">
              <select class="form-control" id="campus" name="campus" required>
                <option value="武汉">武汉</option>
                <option value="长沙">长沙</option>
                <option value="重庆">重庆</option>
                <option value="成都">成都</option>
              </select>
            </div>
          </div>
          <div class="form-group">
            <label for="subject" class="col-sm-2 control-label">学科</label>
            <div class="col-sm-10">
              <select name="subject" class="form-control" id="subject">
                <option value="java">java</option>
                <option value="前端">前端</option>
                <option value="UI">UI</option>
                <option value="python">python</option>
              </select>
            </div>
          </div>
          <div class="form-group">
            <label for="teacher" class="col-sm-2 control-label">导师姓名</label>
            <div class="col-sm-10">
              <input
                type="text"
                class="form-control"
                id="teacher"
                name="teacher"
                placeholder="导师姓名"
                required
              />
            </div>
          </div>
          <div class="form-group">
            <label for="date" class="col-sm-2 control-label">授课时间</label>
            <div class="col-sm-10">
              <input
                type="date"
                class="form-control"
                id="date"
                name="date"
                placeholder="授课时间"
                required
              />
            </div>
          </div>
          <div class="form-group">
            <label for="stage" class="col-sm-2 control-label"
              >授课阶段内容</label
            >
            <div class="col-sm-10">
              <input
                type="text"
                class="form-control"
                id="stage"
                name="stage"
                placeholder="授课阶段"
                required
              />
            </div>
          </div>

          <div class="form-group">
            <label for="duration" class="col-sm-2 control-label"
              >授课时长</label
            >
            <div class="col-sm-10">
              <input
                type="number"
                class="form-control"
                id="time"
                name="time"
                placeholder="授课时长(分钟)"
                min="1"
                required
              />
            </div>
          </div>

          <div class="form-group">
            <label for="url" class="col-sm-2 control-label">视频链接</label>
            <div class="col-sm-10">
              <input
                type="url"
                class="form-control"
                id="url"
                name="url"
                placeholder="视频链接,有提取码时将提取码作为hash,如https://pan.baidu.com/s/1k6VMVP1zOPu0HoODV5kmyQ#3jca 其中3jca为提取码"
                required
              />
            </div>
          </div>

          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              <button type="submit" class="btn btn-primary">提交</button>
              <input
                type="button"
                value="回到列表"
                class="btn btn-info go-list"
              />
            </div>
          </div>
        </form>
      </div>
    </div>
    <script>
      $(function () {
        // 设置日期为当天
        var now = new Date();
        var day = ('0' + now.getDate()).slice(-2);
        var month = ('0' + (now.getMonth() + 1)).slice(-2);
        var today = now.getFullYear() + '-' + month + '-' + day;
        $('#date').val(today);
        // 提交
        $('#add').submit(function (e) {
          e.preventDefault();
          $.post(
            'http://119.45.60.228/info',
            $(this).serialize(),
            function (res) {
              if (res.video_id) {
                Notiflix.Confirm.Init();
                Notiflix.Confirm.Show(
                  '添加成功!',
                  '是否跳转到列表页?',
                  '是',
                  '继续添加',
                  function () {
                    location.href = 'index.html';
                  }
                );
                $('input:text,#time,#url').val('');
              } else {
                Notiflix.Notify.Init();
                Notiflix.Notify.Failure('添加失败!');
              }
            }
          );
        });
        // 回到列表
        $('.go-list').click(function () {
          location.href = 'index.html';
        });
      });
    </script>
  </body>
</html>
